//
//  TextCollectionViewCell.m
//  GOGOTravel
//
//  Created by dllo on 16/2/27.
//  Copyright © 2016年 果果. All rights reserved.
//

#import "TextCollectionViewCell.h"
#import "PICmodel.h"

@interface TextCollectionViewCell ()
@end


@implementation TextCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
       
        self.scrollView = [[UIScrollView alloc] init];
        [self.contentView addSubview:_scrollView];
        [_scrollView release];
        
        
        self.label = [[UILabel alloc] init];
        [_scrollView addSubview:_label];
        [_label release];
        
//        self.view = [[UIView alloc] init];
//        _view.frame = CGRectMake(0, 100, self.frame.size.width, 50);
//        _view.backgroundColor = UIColorFromRGB(0x099cc);
//        [self.contentView addSubview:_view];
//        [_view release];
        
        
    }
    return self;
}

- (void)setModel:(PICmodel *)model{
    
    if (_model != model) {
        [_model release];
        _model = [model retain];
    }
    
    
     _scrollView.contentSize = CGSizeMake(self.frame.size.width - 20, 3000);
    _scrollView.frame = CGRectMake(10, 10, self.frame.size.width - 20, 200);
    //label的自适应高度
    _label.text = _model.text;
    _label.textColor = [UIColor whiteColor];
    NSString *str4 = _model.text;
    _label.numberOfLines = 100;
    //设置字体样式
    NSDictionary *att = @{NSFontAttributeName:[UIFont systemFontOfSize:17]};
    
    CGRect rect = [str4 boundingRectWithSize:CGSizeMake(340, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:att context:nil];
    
    _label.frame = CGRectMake(10, 10 , self.frame.size.width - 20, rect.size.height);
  
}


- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes{
    
    //这个方法是每个cell出现的时候执行 所以要重新设置_scrollView的偏移量
    _scrollView.contentOffset = CGPointMake(10, 0);
   [ super applyLayoutAttributes:layoutAttributes];
    
}




- (void)dealloc{
    [_view release];
    [_scrollView release];
    [_model release];
    [_label release];
    [super dealloc];
}

@end
